package com.ruoyi.security.service.impl;

import java.util.List;
import com.ruoyi.common.core.utils.DateUtils;
import cn.hutool.core.util.IdUtil;
import com.ruoyi.system.api.RemoteBmCodeService;
import com.ruoyi.system.api.domain.RemoteSysBmType;
import com.ruoyi.system.api.enums.SysBmCodeTypeValue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.core.utils.SecurityUtils;
import com.ruoyi.security.mapper.AfExtinguisherMapper;
import com.ruoyi.security.domain.AfExtinguisher;
import com.ruoyi.security.service.IAfExtinguisherService;

/**
 * 灭火器台账Service业务层处理
 *
 * @author felix
 * @date 2022-02-28
 */
@Service
public class AfExtinguisherServiceImpl implements IAfExtinguisherService {
    @Autowired
    private AfExtinguisherMapper afExtinguisherMapper;

    @Autowired
    private RemoteBmCodeService remoteBmCodeService;

    /**
     * 查询灭火器台账
     *
     * @param id 灭火器台账ID
     * @return 灭火器台账
     */
    @Override
    public AfExtinguisher selectAfExtinguisherById(String id) {
        return afExtinguisherMapper.selectAfExtinguisherById(id);
    }

    /**
     * 查询灭火器台账列表
     *
     * @param afExtinguisher 灭火器台账
     * @return 灭火器台账
     */
    @Override
    public List<AfExtinguisher> selectAfExtinguisherList(AfExtinguisher afExtinguisher) {
        return afExtinguisherMapper.selectAfExtinguisherList(afExtinguisher);
    }

    /**
     * 新增灭火器台账
     *
     * @param afExtinguisher 灭火器台账
     * @return 结果
     */
    @Override
    public int insertAfExtinguisher(AfExtinguisher afExtinguisher) {

        RemoteSysBmType remoteSysBmType = remoteBmCodeService.genCode(afExtinguisher.getSysBmId(), SysBmCodeTypeValue.DEVICE);
        String nowCode = remoteSysBmType.getNowCode();//生成的唯一编码
        String deviceType = remoteSysBmType.getHierarchy();//层级
        afExtinguisher.setDevCode(nowCode);

        afExtinguisher.setId(IdUtil.getSnowflake(0, 0).nextIdStr());
        afExtinguisher.setCreateTime(DateUtils.getNowDate());
        afExtinguisher.setCreateBy(SecurityUtils.getUsername());
        return afExtinguisherMapper.insertAfExtinguisher(afExtinguisher);
    }

    /**
     * 修改灭火器台账
     *
     * @param afExtinguisher 灭火器台账
     * @return 结果
     */
    @Override
    public int updateAfExtinguisher(AfExtinguisher afExtinguisher) {
        afExtinguisher.setUpdateTime(DateUtils.getNowDate());
        afExtinguisher.setUpdateBy(SecurityUtils.getUsername());
        return afExtinguisherMapper.updateAfExtinguisher(afExtinguisher);
    }

    /**
     * 批量删除灭火器台账
     *
     * @param ids 需要删除的灭火器台账ID
     * @return 结果
     */
    @Override
    public int deleteAfExtinguisherByIds(String[] ids) {
        return afExtinguisherMapper.deleteAfExtinguisherByIds(ids);
    }

    /**
     * 删除灭火器台账信息
     *
     * @param id 灭火器台账ID
     * @return 结果
     */
    @Override
    public int deleteAfExtinguisherById(String id) {
        return afExtinguisherMapper.deleteAfExtinguisherById(id);
    }
}
